package com.ecloud.service.security.controller;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecloud.common.base.result.Result;
import com.ecloud.common.base.valid.ValidGroup.Delete;
import com.ecloud.common.base.valid.ValidGroup.Insert;
import com.ecloud.common.base.valid.ValidGroup.QueryList;
import com.ecloud.common.base.valid.ValidGroup.Update;
import com.ecloud.openapi.security.dto.BaseMenuDto;
import com.ecloud.service.security.service.iface.IBaseMenuService;

/**
 * 机构菜单表 控制器
 *
 * @author LiuGangQiang Create in 2021/07/04
 */
@RestController
@RequestMapping({ "/base/menu" })
public class BaseMenuController {
    @Resource
    private IBaseMenuService baseMenuService;

    /**
     * 添加菜单
     *
     * @author LiuGangQiang Create in 2021/07/09
     * @param dto 入参
     * @return {@link Result}
     */
    @PostMapping({ "/insert" })
    public Result<?> insert(@Validated({ Insert.class }) @RequestBody BaseMenuDto dto) {
        return baseMenuService.insert(dto);
    }

    /**
     * 删除菜单
     *
     * @author LiuGangQiang Create in 2021/07/09
     * @param id  主键
     * @param dto 入参
     * @return {@link Result}
     */
    @DeleteMapping({ "/delete/{id}" })
    public Result<?> delete(@PathVariable("id") String id, @Validated({ Delete.class }) BaseMenuDto dto) {
        /* 设置参数 */
        dto.setId(id);
        return baseMenuService.delete(dto);
    }

    /**
     * 修改菜单
     *
     * @author LiuGangQiang Create in 2021/07/09
     * @param id  主键
     * @param dto 入参
     * @return {@link Result}
     */
    @PutMapping({ "/update/{id}" })
    public Result<?> update(@PathVariable("id") String id, @Validated({ Update.class }) @RequestBody BaseMenuDto dto) {
        /* 设置参数 */
        dto.setId(id);
        return baseMenuService.update(dto);
    }

    /**
     * 查询菜单
     *
     * @author LiuGangQiang Create in 2021/07/09
     * @param dto 入参
     * @return {@link Result}
     */
    @GetMapping({ "/list" })
    public Result<?> queryList(@Validated({ QueryList.class }) BaseMenuDto dto) {
        return baseMenuService.queryList(dto);
    }

    /**
     * 查询菜单
     *
     * @author LiuGangQiang Create in 2021/07/09
     * @param id  主键
     * @param dto 入参
     * @return {@link Result}
     */
    @GetMapping({ "/detail/{id}" })
    public Result<?> queryDetail(@PathVariable("id") String id) {
        return baseMenuService.queryDetail(id);
    }

}
